﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV.Structure;
using log4net;
using Emgu.CV;

namespace CameraPrpject
{
    public partial class Cemeratow : Form
    {
        public Cemeratow()
        {
            InitializeComponent();
        }

         private VideoCapture capture;
         private bool isProcess = false;
        private void button1_Click(object sender, EventArgs e)
        {
            //创建一张320*240尺寸颜色为红色的图像。imageBox1.Image = image;//在ImageBox1控件中显示所创建好的图像。
            //Image<Bgr, byte> image = new Image<Bgr, byte>(443, 256, new Bgr(0, 0, 255));

            if (capture != null)
            {
                if (isProcess)
                {
                    Application.Idle -= new EventHandler(ProcessFram);
                    this.button1.Text = "停止";
                }
                else
                {
                    Application.Idle += new EventHandler(ProcessFram);
                    this.button1.Text = "开始";
                }
            }
            else
            {
                try
                {
                    capture = new VideoCapture();
                }
                catch (NullReferenceException expt)
                {
                    MessageBox.Show(expt.Message);
                }
            }
        }
        private void ProcessFram(object sender, EventArgs arg)
        {
            imageBox1.Image = capture.QueryFrame();
        }
    }
}
